package com.five.wisdomClass.service.impl;

import com.five.wisdomClass.entity.Course;
import com.five.wisdomClass.entity.Teacher;
import com.five.wisdomClass.mapper.TeacherMapper;
import com.five.wisdomClass.service.ITeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Slf4j
@Service
public class TeacherServiceImpl implements ITeacherService {

    @Autowired
    TeacherMapper teacherMapper;

    // 获取课程列表
    @Override
    public List<Course> getCourses(Teacher teacher) {
        if (teacher == null){
            return null;
        }
        // 获取教师编号
        String teacherNumber = teacher.getTeacherNumber();
        List<Course> courseList = new ArrayList<>();
        // 获取公共课程和选修课程，添加到课程列表，一起返回
        List<Course> publicCourse = teacherMapper.getPublicCourse(teacherNumber);
        List<Course> takeCourse = teacherMapper.getTakeCourse(teacherNumber);
        courseList.addAll(publicCourse);
        courseList.addAll(takeCourse);
        return courseList;
    }
}
